//
//  HRYouXuanViewController.m
//  Economical report
//
//  Created by wyzc on 16/6/27.
//  Copyright © 2016年 叶落知秋. All rights reserved.
//
#define CELLID @"CELL"
#import "HRYouXuanViewController.h"
#import "HRYouXuanModel.h"
#import "HRYouXuanCell.h"
#import "HRNextViewController.h"


@interface HRYouXuanViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIWebViewDelegate>
/**
 *  保存数据
 */
@property(nonatomic,strong)NSArray *array;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;


@end

@implementation HRYouXuanViewController
//懒加载
-(NSArray *)array
{
    if (_array==nil) {
        NSString *path=[[NSBundle mainBundle] pathForResource:@"youXuan.plist" ofType:nil];
        NSArray *arr=[NSArray arrayWithContentsOfFile:path];
        NSMutableArray *arrM = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in arr) {
            HRYouXuanModel *model = [HRYouXuanModel modelWithDict:dict];
            [arrM addObject:model];
        }
        _array=arrM;
       
    }
    return _array;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=HRCOLOR(239, 239, 239);
    self.collectionView.backgroundColor=[UIColor clearColor];
    
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize=CGSizeMake(UPSreenW*0.3, UPSreenH*0.2);
    self.collectionView.contentInset=UIEdgeInsetsMake(50, 10, 50, 10);
    flowLayout.minimumLineSpacing=5;
    flowLayout.minimumInteritemSpacing=5;

    //注册Xib
    UINib *nib=[UINib nibWithNibName:@"HRYouXuanCell" bundle:nil];
    [self.collectionView registerNib:nib forCellWithReuseIdentifier:CELLID];
    self.collectionView.collectionViewLayout=flowLayout;
}
#pragma mark---collectionview的数据源代理方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.array.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HRYouXuanModel *model=self.array[indexPath.row];
//    NSLog(@"%@",model.name);
    HRYouXuanCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:CELLID forIndexPath:indexPath];
    cell.model=model;
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    HRYouXuanModel *model=self.array[indexPath.row];
    HRNextViewController *next=[[HRNextViewController alloc ]init];
    next.model=model;

    [self.navigationController pushViewController:next animated:YES];
   
    
   }
@end
